package proxyDemo01;

import java.lang.reflect.Proxy;

public class ProxyUtils {
    public static StarInterface getProxy(StarInterface star) {
        Object object = Proxy.newProxyInstance(ProxyUtils.class.getClassLoader(), star.getClass().getInterfaces(), (proxy, method, args) -> {
            if (method.getName().equals("sing")) {
                System.out.println("开始代理唱歌");
                return method.invoke(star, args);
            } else if (method.getName().equals("dance")) {
                System.out.println("开始代理跳舞");
            }
            return method.invoke(star, args);
        });
        return (StarInterface) object;
    }
}
